﻿using Quartz;
using Quartz.Spi;
using System;
using System.Collections.Generic;
using System.Text;

namespace SXFramWork.Core.Quartz
{
    /// <summary>
    /// 任务工厂
    /// </summary>
    public class JobFactory : IJobFactory
    {
        private readonly IServiceProvider _container;
        public JobFactory(IServiceProvider serviceProvider)
        {
            _container = serviceProvider;
        }

        public IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler)
        {
            return _container.GetService(bundle.JobDetail.JobType) as IJob;
        }

        public void ReturnJob(IJob job)
        {
            (job as IDisposable)?.Dispose();
        }
    }
}
